import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

public class Main {
    private static int index = 1;
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入运算数值的范围(输入的运算符都是在0-输入运算符之内)");
            int scope = Integer.parseInt(scanner.nextLine());
            StringBuffer operators = new StringBuffer();
            ys: while (true) {
                System.out.println("请输入数值运算符号");
                System.out.println("1.加");
                System.out.println("2.减");
                System.out.println("3.乘");
                System.out.println("4.除");
                System.out.println("5.退出输入符号");
                String fh = scanner.nextLine();
                switch (fh) {
                    case "1" :
                        operators.append("+");
                        break ;
                    case "2" :
                        operators.append("-");
                        break ;
                    case "3" :
                        operators.append("*");
                        break ;
                    case "4" :
                        operators.append("/");
                        break ;
                    case "5" :
                        break ys;
                    default:
                        System.out.println("输入错误");
                }
            }

            System.out.println("请输入出题的数量");
            int count = Integer.parseInt(scanner.nextLine());
            print(scope, operators.toString(), count);
            System.out.println("1.继续输入");
            System.out.println("任意键.退出程序");
            if ("1".equals(scanner.nextLine())) {
            }else{
                return;
            }
        }
    }

    public static void print(int scope, String operators, int count) throws IOException {
        Random random = new Random();
        FileWriter output = null;
        try {
            output = new FileWriter("口算表"+ index +".txt");
            index++;
            for (int i = 0; i < count; i++) {
                int random1 = random.nextInt(scope + 1);
                int random2 = random.nextInt(scope + 1);
                int result = 0;
                double result2 = 0;
                char operator = getOperator(operators);
                if (operator == '+') {
                    result = random1 + random2;
                    output.write(random1 + " + " + random2 + " ⚌ " + result + "\n");
                }else if (operator == '-') {
                    result = random1 - random2;
                    output.write(random1 + " - " + random2 + " ⚌ " + result+ "\n");
                }else if (operator == '*') {
                    result = random1 * random2;
                    output.write(random1 + " × " + random2 + " ⚌ " + result+ "\n");
                }else if (operator == '/') {
                    result2 = (double) random1 / random2;
                    output.write(random1 + " ÷ " + random2 + " ⚌ " + String.format("%.3f", result2) + "\n");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (output != null){
                output.close();
            }
        }
    }
    public static char getOperator(String operators) {
        Random random = new Random();
        int i = random.nextInt(operators.length());
        return operators.charAt(i);
    }
}
